package com.asion.gankapp.model;


import com.asion.gankapp.entrys.BaseEntry;
import com.asion.gankapp.servers.ServiceApi;
import com.asion.gankapp.utils.SetCacheUtils;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
* Created by MVPHelper on 2016/10/05
*/

public class AllTypeModel implements BaseModel{

    public void getDatas(String type,int page,OnGetEntryDatas onGetEntryDatas){
        new Retrofit.Builder()
                .baseUrl("http://gank.io/api/")
                .addConverterFactory(GsonConverterFactory.create())
                .client(SetCacheUtils.setCache())
                .build()
                .create(ServiceApi.class)
                .getAllTypeCommend(type,page).enqueue(new Callback<BaseEntry>() {
            @Override
            public void onResponse(Call<BaseEntry> call, Response<BaseEntry> response) {
                onGetEntryDatas.onGetEntrySuccess(response.body());
            }
            @Override
            public void onFailure(Call<BaseEntry> call, Throwable t) {
                onGetEntryDatas.onGetEntryError("数据请求失败，请检查网络...");
            }
        });
    }


    public interface OnGetEntryDatas{
        void onGetEntrySuccess(Object object);
        void onGetEntryError(String string);
    }

}